﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;

namespace NP.BPMReportPlatform
{
    /// <summary>
    /// 分页实体类
    /// </summary>
    public class PagedAndSortedRequestDto : IValidatableObject
    {
        /// <summary>
        /// 当前页数
        /// </summary>
        [Display(Name = "当前页数")]
        [Required(ErrorMessage = "{0}不能为空！")]
        public int PageIndex { get; set; }

        /// <summary>
        /// 每页最大条数
        /// </summary>
        [Display(Name = "每页最大条数")]
        [Required(ErrorMessage = "{0}不能为空！")]
        public int PageSize { get; set; }

        /// <summary>
        /// 分页字段
        /// </summary>
        public string Sorting { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (PageIndex < 1)
            {
                yield return new ValidationResult("PageIndex不能小于1！", new[] { nameof(PageIndex) });
            }
            if (PageSize < 1)
            {
                yield return new ValidationResult("PageSize不能小于1！", new[] { nameof(PageSize) });
            }

            // 导出用分页逻辑怎么啦
            //if (PageSize > 1000)
            //{
            //    yield return new ValidationResult("PageSize不能大于1000！", new[] { nameof(PageSize) });
            //}
        }
    }
}
